#include "kernel.h"

void *memcpy(void *dest, const void *src, u32int count)
{
    /* Add code here to copy 'count' bytes of data from 'src' to
    *  'dest', finally return 'dest' */
	while(count)
	{
		((uchar *)dest)[count-1] = ((uchar *)src)[count-1];
		if ( ((uchar *)src)[count-1] == 0 )  break ;
		count--;
	}

	return dest;
}

void *memset(void *dest, uchar val, u32int count)
{
    /* Add code here to set 'count' bytes in 'dest' to 'val'.
    *  Again, return 'dest' */
	while(count)
	{
		((uchar*)dest)[count-1] = val;
		count--;
	}
	
	return dest;
}

void *memsetw(void *dest, u16int val, u32int count)
{
    /* Same as above, but this time, we're working with a 16-bit
    *  'val' and dest pointer. Your code can be an exact copy of
    *  the above, provided that your local variables if any, are
    *  unsigned short */
	while(count)
	{
		((u16int*)dest)[count-1] = val;
		count--;
	}
	
	return dest;
}

u32int strlen(const schar *str)
{
    /* This loops through character array 'str', returning how
    *  many characters it needs to check before it finds a 0.
    *  In simple words, it returns the length in bytes of a string */
	u32int  result = 0 ;

	while( str[result] != 0 )
	{
		result ++ ;
	}

	return result;
}